# dependencies.py
from typing import Annotated, Union
from fastapi import Depends, Request, WebSocket

from scorpio.core.common import ScorpioConfig

ConnectionType = Union[Request, WebSocket]

def get_config_dependency(request: Request) -> ScorpioConfig:
    """
    从应用状态获取配置的依赖项
    
    参数:
        request: FastAPI 请求对象
        
    返回:
        应用配置实例
    """
    return request.app.state.config

# 创建可重用的依赖项类型
AppConfigDependency = Annotated[ScorpioConfig, Depends(get_config_dependency)]

# 为WebSocket创建专用的配置依赖项
def get_ws_config_dependency(websocket: WebSocket) -> ScorpioConfig:
    """
    从WebSocket连接的应用状态获取配置
    
    参数:
        websocket: FastAPI WebSocket对象
        
    返回:
        应用配置实例
    """
    # 通过websocket.app访问FastAPI应用实例
    return websocket.app.state.config

WsAppConfigDependency = Annotated[ScorpioConfig, Depends(get_ws_config_dependency)]